import 'package:shop/common/shop_material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class MyWeb extends StatefulWidget {
  final String url;
  MyWeb({Key key, this.url}) : super(key: key);
  @override
  _MyWebState createState() => _MyWebState();
}

class _MyWebState extends State<MyWeb> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("appbar"),
          elevation: 0,
        ),
        body: WebView(
          initialUrl: widget.url,
          javascriptMode: JavascriptMode.unrestricted,
          javascriptChannels: {
            JavascriptChannel(
                name: 'valueByson',
                onMessageReceived: (JavascriptMessage message) {
                  print("++++++++++++++++++++++++++++");
                  print(message.message);
                })
          },
          navigationDelegate: (NavigationRequest request) {
            print("++++++++++++++++++============================+");
            if (request.url.startsWith("myapp://")) {
              print("即将打开 ${request.url}");

              return NavigationDecision.prevent;
            }
            return NavigationDecision.navigate;
          },
          onWebViewCreated: (WebViewController webViewController) {},
        ));
  }
}
